package Pronostics.tests;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

import java.util.ArrayList;

import org.junit.Before;
import org.junit.Test;

import Pronostics.Player;
import Pronostics.PlayerList;

public class PlayerListTest {

	private PlayerList p;
	
	@Before
	public void create(){
		p = PlayerList.getInstance();
		p.erase();
	}
	
	@Test
	public void testAdd(){
		p.add("toto");
		assertEquals("toto",p.getPlayer("toto").getName());
	}
	
	@Test
	public void testExist(){
		p.add("toto");
		assertEquals(p.exist("toto"), true);
		assertEquals(p.exist(""), false);
	}
	
	@Test
	public void testGetSize(){
		p.add("toto");
		p.add("titi");
		assertEquals(p.getSize(), 2);
	}
	
	@Test
	public void testGetListe(){
		ArrayList<Player> liste = new ArrayList<Player>();
		p.add("toto");
		liste.add(new Player("toto"));
		p.add("titi");
		liste.add(new Player("titi"));
		assertEquals(liste.get(0).getName(), p.getPlayerList().get(0).getName());
		assertEquals(liste.get(1).getName(), p.getPlayerList().get(1).getName());
	}
	
	@Test
	public void testGetPlayerAt(){
		p.add("toto");
		assertEquals("toto", p.getPlayer(0).getName());
	}
	
	@Test
	public void testGetBestDay(){
		p.add("toto");
		Player p1 = p.getPlayer("toto");
		p.add("titi");
		Player p2 = p.getPlayer("titi");
		p1.setDayResult(50);
		p2.setDayResult(20);
		assertEquals(p.getBestDay().getName(), "toto");
		assertFalse(p.getBestDay().getName().equals("titi"));
	}
	
	@Test
	public void testGetBestDay2(){
		assertEquals(p.getBestDay(),null);
	}
	
	@Test
	public void testGetBestTotal(){
		p.add("toto");
		Player p1 = p.getPlayer("toto");
		p.add("titi");
		Player p2 = p.getPlayer("titi");
		p1.setTotalResult(50);
		p2.setTotalResult(20);
		assertEquals(p.getBestTotal().getName(), "toto");
		assertFalse(p.getBestTotal().getName().equals("titi"));
	}
	
	@Test
	public void testGetBestTotal2(){
		assertEquals(p.getBestTotal(), null);
	}
}
